/***************************************************************************
 * 
 * Copyright (c) 2012 Baidu.com, Inc. All Rights Reserved
 * common.h,v 1.0 2012-08-17 11:27 yelu01 
 * 
 **************************************************************************/
 
 
 
/**
 * @file perf_test.h
 * @author yelu01(yelu01@baidu.com)
 * @date 2012-08-17 11:28
 * @version 1.0 
 * @brief tools for measure run time between a piece of code.
 *  
 **/

#pragma once

#include "log.h"

#ifdef _PERFOMTEST
#include <sys/time.h>

#define PERFORM_TEST_BEGIN(label) \
timeval start##label; \
gettimeofday(&start##label, NULL); \
do{}while(0)

#define PERFORM_TEST_END(label) \
timeval end##label; \
gettimeofday(&end##label, NULL); \
long timeuse##label = 1000000 * (end##label.tv_sec - start##label.tv_sec) + \
                          end##label.tv_usec - start##label.tv_usec; \
LOG(COMLOG_DEBUG, "PERFORM_TEST:[%s:%ld us]", #label, timeuse##label); \
do{}while(0)

#else
#define PERFORM_TEST_BEGIN(label) do{}while(0)
#define PERFORM_TEST_END(label) do{}while(0)
#endif


